/*------------------------------------------------------------------------------
    JS Document (https://developer.mozilla.org/en/JavaScript)

    project:    Project
    created:    YYYY-MM-DD
    author:     johdoe

    summary:    MAJX_CORE
                CONSTANTES
                UTILITIES
                WINDOW.ONLOAD
                EXAMPLE

----------------------------------------------------------------------------- */

/* =MAJX_CORE (http://code.google.com/p/majx-js/)
----------------------------------------------------------------------------- */
(function(){if(typeof majx=="undefined"){majx={};majx.init=function(){if(!majx.config){majx.config={};}}();}}());majx.set=function(){var e=arguments[0]||{};var b=null;var d=arguments.length;var c=1;if(d==c){e=majx.config;--c;}for(;c<d;c++){if((b=arguments[c])!=null){for(var a in b){var f=e[a];var g=b[a];if(e===g){continue;}else{if(g!==undefined){e[a]=g;}}}}}majx.config=e;};


/*  =CONSTANTES
----------------------------------------------------------------------------- */
jQuery.noConflict();
var d = document;
var w = window;
pm = {};
majx.set({
    /*firebuglite : {
        active : false, // disable (false) in production environment
        url : 'js/firebug-lite-modem.js'
    }*/
});


/*  =UTILITIES
----------------------------------------------------------------------------- */
var log = function(x) {
    if (typeof console != 'undefined') {
        console.log(x);
    }
};



/*  =WINDOW.ONLOAD
----------------------------------------------------------------------------- */
jQuery(document).ready(function(){

    // Call Functions
    pm.carousel();
	pm.menuDeroulant();
	//pm.scrollElt();
	pm.curseurDate();
	pm.scrollToMe('.bt-top');
	
});


/*  =CAROUSEL
----------------------------------------------------------------------------- */
pm.carousel = function() {
	
	jQuery("#foo2").carouFredSel({
		circular: false,
		infinite: true,
		auto    : true,
		scroll  : {
			fx   : "crossfade",
			duration : 1000,
			easing: "linear"
		},
		pagination	: "#foo2_pag"
	});
	
};


/*  =MENU DEROULANT
----------------------------------------------------------------------------- */
pm.menuDeroulant = function(){
	var elt		= jQuery('.menu-deroulant');
	var eltBt	= jQuery('.menu-deroulant .field-01');
	var eltList	= jQuery('.menu-deroulant ul');
	
	eltList.hide();
	
	elt.hover(
		function(){
			jQuery(this).find('ul').show();		   
		},
		function(){
			jQuery(this).find('ul').hide();	
		}
	);
}


/*  =curseur date
----------------------------------------------------------------------------- */
pm.curseurDate = function(){
	var curseur 	= jQuery('.curseur');
	var curseurVal 	= jQuery('.curseur p');
	var titleDate	= jQuery('.ref-date');
	var	barreFiltre	= jQuery(".scroll");
	if(jQuery('.block-mobile').length){
		var conteneur	= jQuery('.page-inner').eq(1);
	}else {
		var conteneur	= jQuery('.page-inner').eq(0);		
	}
	var contentHtml	= '<a href="#content" class="bt-top"><img src="img/data/bt-top.png" alt="haut de page" /></a>';
	conteneur.append(contentHtml);
	var btTop 		= jQuery('.bt-top');
	
	jQuery(window).scroll(function(){
		if(jQuery('html,body').scrollTop()>300 || document.body.scrollTop>300){
			barreFiltre.addClass('fixe');
			curseur.addClass('fixe');
			btTop.fadeIn();
		}else {
			barreFiltre.removeClass('fixe');	
			curseur.removeClass('fixe');
			btTop.fadeOut();
		}
		
		titleDate.each(function(){
			var posDate 	= jQuery(this).offset().top;
			var posCurseur	= curseur.offset().top;
			if(posDate<posCurseur){
				curseurVal.html(jQuery(this).html());	
			}
		});
		
		console.log(btTop.offset().top);
		console.log(jQuery('html,body').height()-79);		
		if(btTop.offset().top > jQuery('html,body').height()-150){
			btTop.addClass('limite');
		}else {
			btTop.removeClass('limite');	
		}
	});
	
}


/*  =Top page
----------------------------------------------------------------------------- */
pm.scrollToMe = function(classname) {
    var sourceLink = jQuery(classname);
    if(sourceLink.length > 0) {
        sourceLink.bind('click', function(){
            var id = jQuery(this).attr('href').split('#')[1];
            jQuery('html,body').animate({scrollTop: jQuery('#'+id).offset().top},500);
            return false;
        });
    }
};

